<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace longbingcore\wxcore;

class WxMsg
{
    protected static $uniacid;
    public function __construct($uniacid)
    {
        self::$uniacid = $uniacid;
        $this->config = $this->getConfig($uniacid);
        $this->appid = $this->getAppid();
    }
    public function WxMsg($to_user, $title = "", $page = "", $description = "", $content_item = "")
    {
        $data = ["touser" => $to_user, "msgtype" => "miniprogram_notice", "miniprogram_notice" => ["appid" => $this->appid]];
        if(!empty($page)) {
            $data["miniprogram_notice"]["page"] = $page;
        }
        if(!empty($title)) {
            $data["miniprogram_notice"]["title"] = $title;
        }
        if(!empty($content_item)) {
            $data["miniprogram_notice"]["content_item"] = $content_item;
        }
        if(!empty($description)) {
            $data["miniprogram_notice"]["description"] = $description;
        }
        $service_model = new WxSetting(self::$uniacid);
        $result = $service_model->sendCompanyMsg($data);
        return $result;
    }
    protected function getAppid()
    {
        if(isset($this->config["appid"])) {
            return $this->config["appid"];
        }
        return NULL;
    }
    protected function getAppsecret()
    {
        if(isset($this->config["app_secret"])) {
            return $this->config["app_secret"];
        }
        return NULL;
    }
    public function getConfig($uniacid)
    {
        $key = "longbing_card_app_config_" . $uniacid;
        $config = getCache($key, $uniacid);
        if(!empty($config)) {
            return $config;
        }
        $config = \think\facade\Db::name("longbing_card_config")->where(["uniacid" => $uniacid])->find();
        if(empty($config)) {
            \think\facade\Db::name("longbing_card_config")->insert(["uniacid" => $uniacid]);
            $config = \think\facade\Db::name("longbing_card_config")->where(["uniacid" => $uniacid])->find();
        }
        if(!empty($config)) {
            setCache($key, $config, 3600, $uniacid);
        }
        return $config;
    }
}

?>